<div class="container"
     data-controller="contest">

  <% if flash[:notice].present? %>
    <%= render "shared/notice", message: flash[:notice] %>
  <% end %>

  <div class="pt-4 d-flex justify-content-between align-items-start">
    <div>
      <h3 class="contest-header-title">
        <%= t("contest.contest_container.contest_id_with_number", id: @contest.id) %>
      </h3>

      <p class="mb-0 contest-header-description">
        <%= t("contest.show.subtitle", user_count: @user_count) %>
      </p>

      <%= link_to leaderboard_contest_path(@contest.id),
                  class: "contest-submission-button text-decoration-none d-inline-block mt-3" do %>
        <span><%= t("contest.show.view_leaderboard", default: "View Leaderboard") %></span>
      <% end %>

      <% if @contest.live? && current_user.present? %>
        <p class="mb-0 contest-header-description mt-2">
          <%= t("contest.show.remaining_votes") %>
          <%= 3 - current_user.votes_for_contest(@contest.id) %>
        </p>
      <% end %>
    </div>

    <% if @contest.live? %>
      <div class="d-flex flex-column align-items-center align-items-md-end">
        <span class="contest-header-timer mb-2">
          <%= t("contest.header.time_left_label") %>
          <% if @contest.deadline.before?(Time.current) %>
            <span><%= t("contest.timer.expired") %></span>
          <% else %>
            <span><%= distance_of_time_in_words(Time.current, @contest.deadline) %></span>
          <% end %>
        </span>

        <%= link_to new_contest_submission_path(@contest.id),
                    class: "contest-submission-button submission-button" do %>
          <span><%= t("contest.show.register_button") %></span>
        <% end %>
      </div>
    <% else %>
      <div class="d-flex flex-column align-items-center align-items-md-end">
        <button type="button" class="contest-ended-button" disabled>
          <%= t("contest.show.disable_button") %>
        </button>
      </div>
    <% end %>
  </div>

  <% if @contest.completed? %>
    <div class="contest-page-line"></div>

    <div>
      <h5><%= t("contest.show.winners") %></h5>
      <span class="contest-header-sub-description">
        <%= t("contest.show.winners_description") %>
      </span>
    </div>

    <div id="my-circuits-div" class="row center-row circuit-page">
      <% if @winner.present? %>
        <%= render Contest::SubmissionCardComponent.new(submission: @winner,
                                                        contest: @contest,
                                                        current_user: current_user) %>
      <% end %>
    </div>
  <% end %>

  <% if @user_submission.present? %>
    <div class="contest-page-line"></div>

    <div>
      <h5><%= t("contest.show.user_submissions") %></h5>
      <span class="contest-header-sub-description">
        <%= t("contest.show.user_submissions_description") %>
      </span>
    </div>

    <div id="my-circuits-div" class="row center-row circuit-page">
      <% @user_submission.each do |submission| %>
        <%= render Contest::SubmissionCardComponent.new(submission: submission,
                                                        contest: @contest,
                                                        current_user: current_user) %>
      <% end %>
    </div>
  <% end %>

  <div class="contest-page-line"></div>

  <div>
    <h5>
      <%= t("contest.show.contest_entries",
             submission_count: @contest.submissions.count) %>
    </h5>
    <span class="contest-header-sub-description">
      <%= t("contest.show.contest_entries_description") %>
    </span>
  </div>

  <div id="my-circuits-div" class="row center-row circuit-page">
    <% @submissions.each do |submission| %>
      <%= render Contest::SubmissionCardComponent.new(submission: submission,
                                                      contest: @contest,
                                                      current_user: current_user) %>
    <% end %>
  </div>

  <div class="container pagination-cont">
    <%= will_paginate @submissions, renderer: PaginateRenderer %>
  </div>

  <%= render Contest::PreviewModalComponent.new %>

  <%= render Contest::WithdrawModalComponent.new(contest: @contest,
                                                 submission: @user_submission) %>
</div>
